package com.icss.train_sys_back.service.system_service.impl;

import com.icss.train_sys_back.entity.system_manage.MenuEntity;
import com.icss.train_sys_back.mapper.system_manage.MenuManageMapper;
import com.icss.train_sys_back.service.system_service.MenuManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 小泽
 * @createTime 2025/9/29 14:23
 */
@Service
public class MenuManageServiceImpl implements MenuManageService {
    @Autowired
    private MenuManageMapper menuManageMapper;

    //获取所有菜单列表
    @Override
    public List<MenuEntity> getAllMenus() {
        return menuManageMapper.getAllMenus();
    }


    //分页+条件查询菜单列表
    @Override
    public List<MenuEntity> getListConditions(String menuName, String menuUrl, Integer parentId, Integer isShow) {
        return menuManageMapper.getListConditions(menuName,menuUrl,parentId,isShow);
    }

    //菜单添加
    @Override
    public void add(MenuEntity menu) {
        menuManageMapper.add(menu);
    }

    //菜单更新
    @Override
    public void update(MenuEntity menu) {
        menuManageMapper.update(menu);
    }

    //菜单启用停用状态管理
    @Override
    public void changeStatus(Integer menuId, Integer isShow) {
        menuManageMapper.changeStatus(menuId,isShow);
    }

    //根据menuId 删除菜单
    @Override
    public void delete(Integer menuId) {
        menuManageMapper.delete(menuId);
    }

    //根据RoleId 获取菜单列表进行菜单加载
    @Override
    public List<MenuEntity> getMenusByRoleId(Integer roleId) {
        //先查所有MenuId
        List<Integer> MenuIds = menuManageMapper.getAllMenuIdsByRoleId(roleId);
        //再根据MenuId 查所有的Menu实体类
        return menuManageMapper.getMenusByMenuIds(MenuIds);
    }
}
